package com.desheng.bigdata.flink.batch.sink

import com.desheng.bigdata.flink.batch.transformation.Worker
import org.apache.flink.api.java.io.TextOutputFormat
import org.apache.flink.api.scala._
import org.apache.flink.core.fs.FileSystem.WriteMode
import org.apache.flink.core.fs.Path

/**
  * sink操作之writeFile
  */
object _01Sink2FileOps {
    def main(args: Array[String]): Unit = {
        val env = ExecutionEnvironment.getExecutionEnvironment

        val workers:DataSet[Worker] = env.fromCollection(List(
            Worker(1, "吴延俊", 25, "研发部"),
            Worker(2, "宋建华", 26, "产品部"),
            Worker(3, "崔蒙恩", 58, "小卖部"),
            Worker(4, "小岚岚", 48, "小卖部"),
            Worker(5, "成思远", 68, "后勤部"),
            Worker(6, "李向闪", 26, "产品部")
        ))
//        workers.writeAsCsv(
//            filePath = "file:/E:/data/out/flink/csv",
//            rowDelimiter = "\n",
//            fieldDelimiter = "|",
//            writeMode = WriteMode.OVERWRITE
//        )
        workers.write(
            outputFormat = new TextOutputFormat[Worker](new Path("file:/E:/data/out/flink/format")),
            filePath = "file:/E:/data/out/flink/format",
            writeMode = WriteMode.OVERWRITE
        )

        env.execute()
    }
}
